<template>
  <view class="patentDetails">
    <navTabrBack
      :navbackStyle="['padding-right: 20rpx', 'color: #fff']"
      :title="'专利详情'"
      :titleStyle="['color: #fff']"
    ></navTabrBack>
    <!-- 专利号 -->
    <view class="patentNum">
      <view class="numDetail">专利号：CN{{ rezlBase?.num }}</view>
      <view class="detailItem">
        <view class="patentTitle">专利名称</view>
        <view class="patentText">{{ rezlBase.name }}</view>
      </view>
      <view class="detailItem">
        <view class="patentTitle">专利类型</view>
        <view class="patentText">{{ rezlBase.desc }}</view>
      </view>
      <view class="detailItem">
        <view class="patentTitle">ipc分类号</view>
        <view class="patentText">{{ rezlBase.type }}</view>
      </view>
      <view class="detailItem">
        <view class="patentTitle">申请人</view>
        <view class="patentText">{{ rezlBase.applyName }}</view>
      </view>
      <view class="detailItem">
        <view class="patentTitle">发明人</view>
        <view class="patentText">{{ rezlBase.inventor }}</view>
      </view>
      <view class="detailItem">
        <view class="patentTitle">专利状态</view>
        <view class="patentText">{{ array[rezlBase.isEmpowered] }}</view>
      </view>
      <view class="detailItem">
        <view class="patentTitle">更新日期</view>
        <view class="patentText">{{ rezlBase.UpdatedAt?.split("T")[0] }}</view>
      </view>
      <view class="detailItem">
        <view class="patentTitle">授权公告日</view>
        <view class="patentText">{{ rezlBase.authDate?.split("T")[0] }}</view>
      </view>
      <view class="detailItem">
        <view class="patentTitle">申请日</view>
        <view class="patentText">{{ rezlBase.applyDate?.split("T")[0] }}</view>
      </view>
      <view class="detailItem">
        <view class="patentTitle">办登截止日</view>
        <view class="patentText">{{ rezlBase.recoverDate?.split("T")[0] }}</view>
      </view>
      <view class="detailItem">
        <view class="patentTitle">恢复截止日</view>
        <view class="patentText">{{ rezlBase.registerDate?.split("T")[0] }}</view>
      </view>
      <view class="detailItem">
        <view class="patentTitle">专利到期日</view>
        <view class="patentText">{{ rezlBase.endDate?.split("T")[0] }}</view>
      </view>
    </view>
    <!-- 专利描述 -->
    <view class="patentDeict">
      <view class="deictTitle"> 专利摘要 </view>
      <view class="mainText">
        {{ rezlBase.summary }}
      </view>
    </view>
    <!-- 专利摘要 -->
    <!-- <view class="patentDeict">
      <view class="deictTitle"> 专利描述 </view>
      <view class="mainText">
        一种用于农业改良土壤的农业设备一种用于农业改良土壤的农业设
        备一种用于农业改良土壤的农业设备一种用于农业改良土壤的农业
        设备一种用于农业改良土壤的农业设备一种用于农业改良土壤的农
        业设备一种用于农业改良土壤的农业设备一种用于农业改良土壤的
        农业设备一种用于农业改良土壤的农业设备一种用于农业改良土壤 的农业设备
      </view>
      "rezlBase": { "ID": 1, 
      "CreatedAt": "2023-03-21T15:17:22.342+08:00",
       "UpdatedAt": "2023-03-21T15:17:22.342+08:00",
        "applyName": "上海伽盒人工智能科技有限公司", 
        "auditStatus": 0, 
        "collectNum": 0, 
        "desc": "本发明涉及一种人工智能伤口评估综合管理系统，节省人力资源、提高效率和准确率。",
         "endTime": "2023-03-31T00:00:00+08:00", 
         "name": "人工智能伤口评估综合管理系统",
          "num": "CN202010376578.2", 
          "status": 0,
           "type": "G06K9/00",
            "userId": 1 } 
    </view> -->
    <!-- 按钮 -->
    <button
      type="primary"
      @click="open"
      class="addPatent"
      v-if="rezlBase.auditStatus == 1"
    >
      添加到专利集
    </button>
    <!-- 普通弹窗 -->
    <view>
      <uni-popup ref="popup" type="bottom" :mask-click="true">
        <view class="dataList">
          <view class="addItemTitle">添加到专利集</view>
          <scroll-view scroll-y="true" class="scroll-Y">
            <!-- 添加条数 -->
            <view
              class="addItem"
              v-for="(item, index) in dataList"
              :key="index"
              @click="addDataList(item.ID)"
            >
              <view
                v-if="item.img.length != 0 ? false : true"
                class="iconfont icon--jia"
              ></view>
              <image
                v-if="item.img.length != 0 ? true : false"
                :src="img + item.img"
                mode="scaleToFill"
              />
              <view>
                <view class="addName">{{ item.name }}</view>
                <view class="addNum">{{ item.orderNum }}条</view>
              </view>
            </view>
          </scroll-view>
        </view>
      </uni-popup>
    </view>
  </view>
  <!-- 提示信息弹窗 -->
  <uni-popup ref="success3" type="message">
    <uni-popup-message
      type="success"
      message="添加专利集成功！"
      :duration="1000"
    ></uni-popup-message>
  </uni-popup>
  <!-- 提示信息弹窗 -->
  <uni-popup ref="success" type="message">
    <uni-popup-message
      type="error"
      message="当前专利集已添加该专利！"
      :duration="1000"
    ></uni-popup-message>
  </uni-popup>
</template>

<script setup>
import { reactive, onMounted, toRefs, ref, inject } from "vue";
import { onLoad } from "@dcloudio/uni-app";
const $url = inject("$url");
const $imgSrc = inject("$imgSrc");
let popup = ref();
let data = reactive({
  rezlBase: {},
  dic: [],
  userInfo: {},
  img: "",
  id: 1,
  dataList: [],
  array: ["授权未下证", "已下证"],
  addData: {
    groupId: 1, //专利集主键ID
    baseNum: [], //多个专利ID
  },
});
let success3 = ref();
let success = ref();
let { rezlBase, dataList, array, img } = toRefs(data);
const open = () => {
  data.dataList = [];
  uni.getStorage({
    key: "useInfo",
    fail: (err) => {
      console.log(err);
      uni.navigateTo({
        url: "/pages/login/login?type=1",
      });
    },
    success: function (res) {
      data.userInfo = res.data;

      uni.request({
        url:
          $url +
          `/zlGroup/getZlGroupList?page=1&pageSize=100&userId=${data.userInfo.ID}&status=3`,
        method: "GET",
        timeout: 6000,
        header: {
          "x-token": res.data.token,
        },
        fail: (err) => {
          console.log(err, "请求失败！");
        },
        success(res) {
          console.log(res);
          res.data.data.list.map((item) => {
            data.dataList.push(item);
          });
        },
      });
    },
  });
  popup.value.open("button-text");
};
const addDataList = (id) => {
  data.addData.groupId = id * 1;
  data.addData.baseNum = [data.rezlBase.num];
  uni.request({
    url: $url + `/zlCollect/createZlCollect`,
    method: "POST",
    timeout: 6000,
    header: {
      "x-token": data.userInfo.token,
    },
    data: data.addData,
    fail: (err) => {
      console.log(err, "请求失败！");
    },
    success(res) {
      if( res.data.code == 7) {
        success.value.open();
      } else {
        success3.value.open();
      }
    },
  });
  popup.value.close();
};
onLoad((item) => {
  const { id, type } = item
  data.img = $imgSrc;
  uni.request({
    url: $url + `/zlBaseType/getZlBaseTypeList `,
    method: "GET",
    timeout: 6000,
    fail: (err) => {
      console.log(err, "请求失败！");
    },
    success(res) {
      data.dic = res.data.data.list;
      pullPatentDtill(id, type);
    },
  });
});
// 获取详细专利信息
const pullPatentDtill = (id, types) => {
  console.log(id,types);
  // 请求专利推荐数据
  if (types == 1) {
    uni.request({
      url: $url + `/base/findZlBaseProd?num=${id}`,
      method: "GET",
      timeout: 6000,
      fail: (err) => {},
      success(res) {
        data.dic.map((item) => {
          if (item.ID == res.data.data?.rezlBase?.isEmpowered) {
            res.data.data.rezlBase.desc = item.id;
          }
        });
        data.rezlBase = res.data.data.rezlBaseProd;
        data.rezlBase.auditStatus = 1
      },
    });
  } else {
    uni.request({
      url: $url + `/base/findZlBase?ID=${id}`,
      method: "GET",
      timeout: 6000,
      fail: (err) => {},
      success(res) {
        // data.dic.map((item) => {
        //   if (item.ID == res.data.data.rezlBase.isEmpowered) {
        //     res.data.data.rezlBase.desc = item.id;
        //   }
        // });
        data.rezlBase = res.data.data.rezlBase;
      },
    });
  }
};
</script>

<style scoped>
.patentDetails {
  background-image: url("");
  background-repeat: no-repeat;
  background-size: 100%;
  min-height: 410rpx;
  padding: 0 28rpx;
  padding-bottom: 40rpx;
}
.patentNum {
  margin: 28rpx auto 36rpx auto;
  width: 694rpx;
  padding-bottom: 25rpx;
  background: #ffffff;
  box-shadow: 0rpx 2rpx 7rpx 0rpx #ebebeb;
  border-radius: 11rpx;
}
.numDetail {
  height: 72rpx;
  background: #f1f7ff;
  border-radius: 11rpx 11rpx 0rpx 0rpx;
  padding: 18rpx 0 0 36rpx;
  margin-bottom: 18rpx;
}
.detailItem {
  padding: 0 32rpx 0 36rpx;
  display: flex;
  margin-bottom: 15rpx;
}
.patentTitle {
  font-size: 25rpx;
  font-weight: 400;
  color: #999999;
}
.patentText {
  flex: 1;
  width: 500rpx;
  font-size: 25rpx;
  font-weight: 400;
  color: #333333;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.patentDeict {
  width: 694rpx;
  background: #ffffff;
  box-shadow: 2rpx 2rpx 11rpx 0rpx rgba(235, 235, 235, 0.5), 0rpx 2rpx 7rpx 0rpx #e8e8e8;
  border-radius: 11rpx;
  margin-bottom: 38rpx;
  padding-bottom: 24rpx;
}
.deictTitle {
  height: 80rpx;
  font-size: 29rpx;
  font-weight: 400;
  color: #333333;
  line-height: 80rpx;
  margin-left: 29rpx;
  margin-right: 32rpx;
  border-bottom: 4rpx dashed #999999;
}
.mainText {
  padding: 26rpx 24rpx 10rpx 28rpx;
  font-size: 22rpx;
  font-weight: 400;
  color: #999999;
}
/* 按钮 */
.addPatent {
  height: 91rpx;
  line-height: 91rpx;
  background: #1677ff;
  box-shadow: 2rpx 2rpx 9rpx 0rpx #c3c3c5;
  border-radius: 44rpx;
  font-size: 29rpx;
  font-weight: 400;
  color: #ffffff;
  margin-bottom: 30rpx;
}
/* 添加专利集 */
.dataList {
  width: 100%;
  height: 645rpx;
  background: #ffffff;
  border-radius: 11rpx 11rpx 0rpx 0rpx;
}
.addItemTitle {
  display: flex;
  align-items: center;
  height: 108rpx;
  border-bottom: 2rpx solid #dfdfdf;
  padding-left: 27rpx;
  font-size: 33rpx;
  font-weight: 700;
  color: #333333;
  margin-bottom: 18rpx;
}
.scroll-Y {
  height: 480rpx;
}
.addItem {
  margin: 0 32rpx 18rpx 27rpx;
  display: flex;
  align-items: center;
}
.addItem image,
.addItem .iconfont {
  margin-right: 27rpx;
  width: 109rpx;
  height: 109rpx;
  background: #e5e3e6;
  border-radius: 14rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 50rpx;
  color: #999999;
}
.addName {
  font-size: 29rpx;
  width: 500rpx;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 400;
  color: #333333;
}
.addNum {
  margin-top: 8rpx;
  font-size: 25rpx;
  font-weight: 400;
  color: #888888;
}
</style>
